<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <input type="text" placeholder="姓名" v-model="emp.name">
    <input type="text" placeholder="工资" v-model="emp.salary">
    <input type="text" placeholder="工作" v-model="emp.job">
    <input type="button" value="添加" @click="f()">
    <table border="1">
        <caption>员工列表</caption>
        <tr>
            <th>姓名</th><th>工资</th><th>工作</th>
        </tr>
        <tr v-for="employ in arr">
            <td>{{employ.name}}</td><td>{{employ.salary}}</td><td>{{employ.job}}</td>
        </tr>
    </table>
</div>
<!--引入框架-->
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
                el:"div",
                data:{
                    arr:[
                        {name:"张三",salary:3000,job:"销售"},
                        {name:"李四",salary:4000,job:"人事"},
                        {name:"王五",salary:10000,job:"程序员"}],
                    emp:{   //封装
                        name:"",
                        salary:"",
                        job:""
                    }
                },
                methods:{
                    f(){
                        //push()是JavaScript中数组里面的添加方法
                        // v.arr.push(v.emp);
                        //  v.arr.push({name:"赵六",salary:"10000",job:"程序员"})

                        /*
                        * JSON.parse(JSON.stringify(v.emp))创建了一个新的对象添加到数组中
                        * 此时emp对象的值发生改变和数组中的新对象是无关的,
                        * 这种复制出来的和原对象无关的方式称为深拷贝(有引用关系的是浅拷贝)
                        */
                        v.arr.push(JSON.parse(JSON.stringify(v.emp)));
                    }
                }
            })
</script>
</body>
</html>